package com.yociyy.common.core.msg;

import com.github.pagehelper.PageInfo;
import lombok.*;

import java.io.Serializable;
import java.util.List;

/**
 * 分页响应信息公共对象
 * 
 * @author: YoCiyy
 * @date: 2020/5/1
 */
@Data
public class TableR<T> implements Serializable {
	private static final long serialVersionUID = 1L;

	private int code = 0;

	private TableData<T> data;

	public TableR(List<T> list) {
		PageInfo<?> pageInfo = new PageInfo(list);
		this.data = new TableData<T>(pageInfo.getTotal(), list, pageInfo.getPageNum());
	}

	public TableR(List<T> list, int code) {
		this.code = code;
		PageInfo<?> pageInfo = new PageInfo(list);
		this.data = new TableData<T>(pageInfo.getTotal(), list, pageInfo.getPageNum());
	}

	@AllArgsConstructor
	@NoArgsConstructor
	public class TableData<T> {

		@Getter
		@Setter
		private long total;

		@Getter
		@Setter
		private List<T> rows;

		@Getter
		@Setter
		private long pageNum;
	}
}
